package cc.vv.btpartyjob.jobactivities.activity

import android.support.v4.app.Fragment
import android.support.v4.view.ViewPager
import android.view.View
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.btpartyjob.jnimodule.adapter.JniViewPageAdapter
import cc.vv.btpartyjob.jnimodule.binder.BaseBinder
import cc.vv.btpartyjob.jnimodule.enums.H5UrlEnum
import cc.vv.btpartyjob.jnimodule.fragment.DemonstrationFragment
import cc.vv.btpartyjob.jnimodule.server.JniStartActivity
import cc.vv.btpartyjob.jobactivities.delegate.DemonstrationTypicalActivityDelegate
import cc.vv.btpartyjob.jobactivities.globle.IntentJobKey
import cc.vv.btpartyjob.jobactivities.server.JobActivitiesServer
import cc.vv.mvp.activity.BaseActivityMVP
import cc.vv.mvp.binder.BaseDataBinder
import com.chad.library.adapter.base.BaseQuickAdapter

/**
 * 示范典型
 * Created by Chen.qi on 2018/10/31.
 */
class DemonstrationTypicalActivity : BaseActivityMVP<DemonstrationTypicalActivityDelegate>(){

    /**
     * ViewPager适配器
     */
    private var mAdapter: JniViewPageAdapter? = null

    /**
     * Fragment集合
     */
    private var mFragments: ArrayList<Fragment>? = null

    /**
     * 类型  0 农村党组织 1 社区党组织 2 学校党组织
     * 3 机关党组织 4 非公党组织 5 社会组织党组织 6 国家企事业单位党组织
     */
    private var typeArray: ArrayList<String>? = null

    private var type = 0


    override fun initData() {
        viewDelegate?.setTopBarTitle("示范典型")
        val title = intent.getStringExtra(IntentJobKey.INTENT_JOB_KEY_TITLE)
        when (title) {
            "农村党组织" -> {
                type = 0
            }
            "社区党组织" -> {
                type = 2
            }
            "学校党组织" -> {
                type = 3
            }
            "机关党组织" -> {
                type = 1
            }
            "非公党组织" -> {
                type = 4
            }
            "社会组织党组织" -> {
                type = 5
            }
            "国家企事业单位党组织" -> {
                type = 6
            }
        }
        typeArray = arrayListOf("0", "3", "1", "2", "4", "5", "6")

        mFragments = ArrayList()
        for (i in 0 until 7) {
            val queryFragment = DemonstrationFragment()
            queryFragment.setType(typeArray!![i])
            mFragments!!.add(queryFragment)
        }
        mAdapter = JniViewPageAdapter(supportFragmentManager, mFragments!!,
                JobActivitiesServer.getTypeTitleArrayString())
        viewDelegate?.setAdapterData(mAdapter!!)
        viewDelegate?.initTabLayout()
        viewDelegate?.setViewpagerPos(type)
    }

    override fun bindEvenListener() {
        viewDelegate?.setTitleBackBtnOnClick(object : BaseTopBarView.EventInterface {
            //返回
            override fun leftOnClick() {
                finish()
            }

            override fun leftCloseClick() {}
            override fun rightOnClick() {
            }
        })
        viewDelegate?.bindViewPagerListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {
            }

            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
            }

            override fun onPageSelected(position: Int) {

            }
        })
    }

    override fun getDelegateClass(): Class<DemonstrationTypicalActivityDelegate> {
        return DemonstrationTypicalActivityDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return BaseBinder()
    }

}